package com.tradeplus.admin.dao;

import com.tradeplus.admin.model.Member;
import java.util.List;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class MemberDaoImpl implements MemberDao {

    private HibernateTemplate hibernateTemplate;

    public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
        this.hibernateTemplate = hibernateTemplate;
    }
    
    @Override
    public void deleteMember(Long memberId) {
        hibernateTemplate.delete(hibernateTemplate.get(Member.class, memberId));
    }

    @Override
    public List<Member> loadMember() {
        return hibernateTemplate.find("from Member");
    }

    @Override
    public Member loadMemberById(Long memberId) {
        return (Member) hibernateTemplate.get(Member.class, memberId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void saveMember(Member member) {
        hibernateTemplate.merge(member);
    }
    
    
}
